/*
 *可以使用该优惠券的商品列表
 */
require(['jquery','../modules/pageSize','../modules/popup', 'jqScroller'],function($,pageSetSize,popup){
	//设置html根目录字体大小
    setRootFontSize(pageSetSize);
    var curPagePos = 1;
	 /*$("#cxgoods-progress a").on("click", function(e){
        e.preventDefault();
        if(_isAjaxLoad) return;
        curPagePos++;
        ajaxGoodsList();
    });*/
	/*请求商品列表*/
	jqScroller.render = function(cpage){
        popup.loadPopup("正在加载中...");
        $.ajax({
            type: "GET",
            url: "/Home/Member/apimemberCouponGoodsList"+getFixedExtraUrl(),
            data: {"rule_id" : cur_rule_id, "page" : cpage},
            dataType: "json",
            success: function (rs) {
                popup.removeLoad();
				if(rs && rs.data != null)  {
                    renderGoodsList(rs.data);
					curPagePos++;
                    jqScroller.curPage++;
                    jqScroller.unblock();
                    $("#cxgoods-progress").css("display", "");
                }else{
                    jqScroller.done();
                    $("#cxgoods-progress").css("display", "none");
                    if(curPagePos == 1){
                        $(".new-goods").html("<div class='no-data-txt'>没有数据！</div>");    
                    }else{                        
                        popup.alertPopup("没有更多数据！");
                    }                    
                }              
            },
            error: function () {
                popup.removeLoad();
                popup.alertPopup('服务器异常，请稍后重试！');
                jqScroller.unblock();
            }
        });
    };
    jqScroller.run();
    jqScroller.render(1);	
	/*渲染商品列表*/
	function renderGoodsList(list){
		var output = "";
		var c;
		for(var k in list){
			c = list[k];
			output += '<div class="goods-item clearfix">';
			output += '<a href="/goods/detail/id/'+c["store_pid"]+''+getFixedExtraUrl()+'" class="img"><img src="'+getDefaultImg(c["img_path"])+'"></a>';
			output += '<div class="text">';
			output += '<a href="/goods/detail/id/'+c["store_pid"]+''+getFixedExtraUrl()+'" class="goods-name">'+c["p_name"]+'</a>';
			if(c["spec_info"]){
				output += '<span class="des text-hide">'+c["spec_info"]+'</span>';
			}
			output += '<p class="clearfix"><label class="sale-price">¥'+c["price"]+'</label><label class="old-price">￥'+c["marketprice"]+'</label></p>';
			output += '</div>';
			output += '</div>';
		}
		if(curPagePos % 10 == 0){
			$("#ajax-goodslist").html(output);	
		}else{
			$("#ajax-goodslist").append(output);
		}
	}
});